﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Protocol
{
    public class ReqPlayerInput
    {
        public int LogicFrame;
        public InputCommand InputCommand;
        public static ReqPlayerInput Decode(byte[] buffer)
        {
            ReqPlayerInput input = new ReqPlayerInput();
            using (MemoryStreamExt ms = new MemoryStreamExt(buffer))
            {
                input.LogicFrame = ms.ReadInt();
                InputCommand c = new InputCommand();
                c.PlayerId = ms.ReadInt();
                c.XAxis = ms.ReadFloat();
                c.YAxis = ms.ReadFloat();
                c.InputType = (EInputType)ms.ReadByte();
                c.InputStatus = (EInputStatus)ms.ReadByte();
                input.InputCommand = c;
            }
            return input;
        }

        public byte[] Encode()
        {
            byte[] buffer = null;
            using (MemoryStreamExt ms = new MemoryStreamExt())
            {
                ms.WriteInt(LogicFrame);
                ms.WriteInt(InputCommand.PlayerId);
                ms.WriteFloat(InputCommand.XAxis);
                ms.WriteFloat(InputCommand.YAxis);
                ms.WriteByte((byte)InputCommand.InputType);
                ms.WriteByte((byte)InputCommand.InputStatus);

                buffer = ms.ToArray();
            }
            return buffer;
        }
    }





}
